package com.hanbang.taitaigou.ui.widget.banner;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;


import com.hanbang.taitaigou.model.BannerAdData;
import com.hanbang.taitaigou.utils.http.BitmapUtil;
import com.hanbang.taitaigou.utils.http.HttpLocalUtils;
import com.hanbang.taitaigou.utils.ui.LogUtils;

import org.xutils.x;

/**
 * Created by Sai on 15/8/4.
 * 网络图片加载例子
 */
public class NetworkImageHolderView implements Holder<BannerAdData> {
    private ImageView imageView;

    @Override
    public View createView(Context context) {
        //你可以通过layout文件来创建，也可以像我一样用代码创建，不一定是Image，任何控件都可以进行翻页
        imageView = new ImageView(context);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
        imageView.setLayoutParams(params);
        return imageView;
    }

    @Override
    public void UpdateUI(Context context, int position, BannerAdData data) {
        x.image().bind(imageView, HttpLocalUtils.getHttpFileUrl(data.getImg_url()), BitmapUtil.getImageOptionsBuilder().build());
        LogUtils.e("sssssssssssssss", data.getImg_url());
    }

    @Override
    public View getView() {
        return imageView;
    }

}
